use crate::business::app_state::AppState;
use crate::business::websocket::dto::common_dto::{ExceptionResp, OkResp};
use crate::business::websocket::dto::im_base_dto::{CollectItemList, CollectPullReq, ConfigItemList, ConfigPullReq, FeedbackItemList, FeedbackPullReq, LabelInfoItemList, LabelPullReq, ModuleInfoItemList, ModulePullReq, SensitiveWordItemList, SensitiveWordPullReq};
use crate::business::websocket::dto::im_department_dto::{DepartmentInfoItemList, DepartmentInfoListReq};
use crate::business::websocket::dto::im_group_dto::{GroupInfoItemList, GroupInfoListReq};
use crate::business::websocket::dto::im_message_dto::{MessageActionList, MessageObjectList, MessagePullActionOkReq, MessagePullActionReq, MessagePullByMessageIdsReq, MessagePullBySessionIdsReq, OkListReq};
use crate::business::websocket::dto::im_session_dto::{SessionItemList, SessionPullReq};
use crate::business::websocket::dto::user_dto::{UserInfoItemList, UserInfoListReq};
use crate::business::websocket::send_data_handle::send_data_async;
use crate::business::websocket::send_data_router::{RpcRequest, RpcResponse};

pub struct RpcPullMessageService;

impl RpcPullMessageService {

    pub async fn pull_config_list(&self, app_state: AppState, config_pull_req: ConfigPullReq) -> Result<ConfigItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullConfigs(config_pull_req)).await;
        if let RpcResponse::PullConfigsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_department_list(&self, app_state: AppState, department_info_list_req: DepartmentInfoListReq) -> Result<DepartmentInfoItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullDepartments(department_info_list_req)).await;
        if let RpcResponse::PullDepartmentsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_user_list(&self, app_state: AppState, user_info_list_req: UserInfoListReq) -> Result<UserInfoItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullUsers(user_info_list_req)).await;
        if let RpcResponse::PullUsersResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_group_list(&self, app_state: AppState, group_info_list_req: GroupInfoListReq) -> Result<GroupInfoItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullGroups(group_info_list_req)).await;
        if let RpcResponse::PullGroupsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_module_list(&self, app_state: AppState, module_pull_req: ModulePullReq) -> Result<ModuleInfoItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullModules(module_pull_req)).await;
        if let RpcResponse::PullModulesResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_session_list(&self, app_state: AppState, session_pull_req: SessionPullReq) -> Result<SessionItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullSessions(session_pull_req)).await;
        if let RpcResponse::PullSessionsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_message_list(&self, app_state: AppState, message_pull_by_session_ids_req: MessagePullBySessionIdsReq) -> Result<MessageObjectList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullMessageBySessionIds(message_pull_by_session_ids_req)).await;
        if let RpcResponse::PullMessageBySessionIdsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_message_by_message_ids(&self, app_state: AppState, message_pull_by_message_id_req: MessagePullByMessageIdsReq) -> Result<MessageObjectList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullMessageByServerIds(message_pull_by_message_id_req)).await;
        if let RpcResponse::PullMessageByServerIdsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn ok_messages(&self, app_state: AppState, ok_list_req: OkListReq) -> Result<OkResp, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::OkMessages(ok_list_req)).await;
        if let RpcResponse::OkMessagesResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }


    pub async fn pull_message_action_list(&self, app_state: AppState, message_pull_action_req: MessagePullActionReq) -> Result<MessageActionList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullMessageAction(message_pull_action_req)).await;
        if let RpcResponse::PullMessageActionResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn ok_message_actions(&self, app_state: AppState, message_pull_action_ok_req: MessagePullActionOkReq) -> Result<OkResp, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::OkMessageAction(message_pull_action_ok_req)).await;
        if let RpcResponse::OkMessageActionResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_label_list(&self, app_state: AppState, label_pull_req: LabelPullReq) -> Result<LabelInfoItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullLabes(label_pull_req)).await;
        if let RpcResponse::PullLabesResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_collect_list(&self, app_state: AppState, collect_pull_req: CollectPullReq) -> Result<CollectItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullCollects(collect_pull_req)).await;
        if let RpcResponse::PullCollectsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_feedback_list(&self, app_state: AppState, feedback_pull_req: FeedbackPullReq) -> Result<FeedbackItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullFeedbacks(feedback_pull_req)).await;
        if let RpcResponse::PullFeedbacksResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }

    pub async fn pull_sensitive_word_list(&self, app_state: AppState, sensitive_word_pull_req: SensitiveWordPullReq) -> Result<SensitiveWordItemList, ExceptionResp> {
        let response = send_data_async(app_state.clone(), RpcRequest::PullSensitiveWords(sensitive_word_pull_req)).await;
        if let RpcResponse::PullSensitiveWordsResponse(result) = response {
            return result;
        }

        Err(ExceptionResp::new("缺少对应的处理器".to_string()))
    }
    
}